﻿using MediatR;
using Production_Get.API.Application.Commands.CustomerShow;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.Produce.Customers;
using THE_WIND_RISES.Common.Domans.Produce.DemandPlanning;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.MaterialManagement.MaterialRequirementsPlanning
{
    public class MaterialPlanningMangHandler : IRequestHandler<MaterialPlanningMangCommon, Result>
    {
        private readonly IBaseRepositoryGet<MaterialPlanning> MaterialPlanningRepository;
        public MaterialPlanningMangHandler(IBaseRepositoryGet<MaterialPlanning> materialPlanningRepository)
        {
            MaterialPlanningRepository = materialPlanningRepository;
        }

        public async Task<Result> Handle(MaterialPlanningMangCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };

            string sql = "SELECT * FROM MaterialPlanning where MaterialPlanningId=" + request.MaterialPlanningId;
            var list = MaterialPlanningRepository.GetAll(sql, default).FirstOrDefault();
            if (list != null)
            {
                result.Code = (int)CommonErrorCodes.Success;
                result.Data = list;
                result.Msg = "反填成功";
            }

            return result;
        }
    }
}
